home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Startup Screen Picker 1.2 / source / ssp startup app ƒ / ssp code ƒ / ssp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  5.7 KB  |  190 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        sfx.c
  4.  
  5. Purpose:    This module is a dispatch for installing the shutdown
  6.             procs and fade module.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "ssp.h"
  26. #include "program globals.h"
  27. #include "prefs.h"
  28.  
  29. unsigned char        gLastName[32];
  30.  
  31. static short DoSSThing(void);
  32.  
  33. short DoSetup(void)
  34. {
  35.     short            resultCode;
  36.     
  37.     resultCode=PreferencesInit();
  38.     if ((resultCode==prefs_allsWell) || (resultCode==prefs_virginErr))
  39.     {
  40.         resultCode=DoSSThing();
  41.     }
  42.     
  43.     return resultCode;
  44. }
  45.  
  46. short DoSSThing(void)
  47. {
  48.     OSErr            isHuman;
  49.     CInfoPBRec        pb_file, pb_dir;
  50.     HParamBlockRec    pb_basic, pb_new;
  51.     CMovePBRec        pb_move;
  52.     short            vRefNum;
  53.     long            parID;
  54.     short            i;
  55.     long            temp;
  56.     unsigned char    newName[32];
  57.     Boolean            gotone;
  58.     
  59.     isHuman=FindFolder(kOnSystemDisk, kSystemFolderType, kDontCreateFolder, &vRefNum,
  60.                 &parID);                    /* find system folder */
  61.     if (isHuman!=noErr)
  62.         return cantFindSystemFolderErr;
  63.     
  64.     pb_dir.dirInfo.ioCompletion=0L;
  65.     pb_dir.dirInfo.ioNamePtr="\pStartup Screens";
  66.     pb_dir.dirInfo.ioVRefNum=vRefNum;
  67.     pb_dir.dirInfo.ioFDirIndex=0; /* very important */
  68.     pb_dir.dirInfo.ioDrDirID=parID;
  69.     isHuman=PBGetCatInfo(&pb_dir, FALSE);    /* get info on "Startup Screens" dir */
  70.     if (isHuman!=noErr)
  71.         return cantGetDirInfoErr;
  72.     
  73.     if (pb_dir.dirInfo.ioDrNmFls==0)        /* any files in "Startup Screens" dir? */
  74.         return noFilesErr;
  75.     
  76.     gotone=FALSE;
  77.     for (i=0; ((i<pb_dir.dirInfo.ioDrNmFls) && (!gotone)); i++)
  78.     {
  79.         pb_new.fileParam.ioCompletion=0L;
  80.         pb_new.fileParam.ioNamePtr=newName;
  81.         pb_new.fileParam.ioVRefNum=vRefNum;
  82.         pb_new.fileParam.ioFDirIndex=i+1;
  83.         pb_new.fileParam.ioDirID=pb_dir.dirInfo.ioDrDirID;
  84.         isHuman=PBGetCatInfo(&pb_new, FALSE);
  85.         if (isHuman!=noErr)
  86.             return cantGetNewFileInfoErr;
  87.         if (!(pb_new.fileParam.ioFlFndrInfo.fdFlags&fInvisible))
  88.             gotone=TRUE;    /* found visible file in "Startup Screens" folder */
  89.     }
  90.     
  91.     if (!gotone)
  92.         return noFilesErr;
  93.     
  94.     do
  95.     {
  96.         pb_new.fileParam.ioCompletion=0L;
  97.         pb_new.fileParam.ioNamePtr=newName;
  98.         pb_new.fileParam.ioVRefNum=vRefNum;
  99.         GetDateTime(&temp);
  100.         pb_new.fileParam.ioFDirIndex=(temp&0x7fffffff)%pb_dir.dirInfo.ioDrNmFls+1;
  101.         pb_new.fileParam.ioDirID=pb_dir.dirInfo.ioDrDirID;
  102.         isHuman=PBGetCatInfo(&pb_new, FALSE);    /* get info on random file in */
  103.         if (isHuman!=noErr)                        /* "Startup Screens dir */
  104.             return cantGetNewFileInfoErr;
  105.     }
  106.     while (pb_new.fileParam.ioFlFndrInfo.fdFlags&fInvisible);
  107.     
  108.     pb_basic.fileParam.ioCompletion=0L;
  109.     pb_basic.fileParam.ioNamePtr=gLastName;
  110.     pb_basic.fileParam.ioVRefNum=vRefNum;
  111.     pb_basic.fileParam.ioDirID=parID;
  112.     pb_basic.fileParam.ioFDirIndex=0;
  113.     isHuman=PBGetCatInfo(&pb_basic, FALSE);
  114.     if (isHuman!=noErr)
  115.     {
  116.         pb_basic.fileParam.ioFlFndrInfo.fdFlags&=~0x0100;    /* clear 'initted' flag */
  117.         pb_basic.fileParam.ioCompletion=0L;
  118.         pb_basic.fileParam.ioNamePtr=gLastName;
  119.         pb_basic.fileParam.ioVRefNum=vRefNum;
  120.         pb_basic.fileParam.ioDirID=parID;
  121.         pb_basic.fileParam.ioFDirIndex=0;
  122.         PBSetCatInfo(&pb_basic, FALSE);
  123.     }
  124.     
  125.     pb_basic.fileParam.ioCompletion=0L;
  126.     pb_basic.fileParam.ioNamePtr="\pStartupScreen";
  127.     pb_basic.fileParam.ioVRefNum=vRefNum;
  128.     pb_basic.ioParam.ioMisc=gLastName;
  129.     pb_basic.fileParam.ioDirID=parID;
  130.     isHuman=PBHRename(&pb_basic, FALSE);    /* rename "StartupScreen" to saved name */
  131.     if ((isHuman!=noErr) && (isHuman!=fnfErr))
  132.         return cantRenameStartupScreenErr;
  133.     
  134.     if (isHuman!=fnfErr)
  135.     {
  136.         pb_move.ioCompletion=0L;
  137.         pb_move.ioNamePtr=gLastName;
  138.         pb_move.ioVRefNum=vRefNum;
  139.         pb_move.ioNewName=0L;
  140.         pb_move.ioNewDirID=pb_dir.dirInfo.ioDrDirID;
  141.         pb_move.ioDirID=pb_basic.fileParam.ioDirID;
  142.         isHuman=PBCatMove(&pb_move, FALSE);    /* move old one into "Startup Screens" dir */
  143.         if (isHuman!=noErr)
  144.             return cantMoveStartupScreenErr;
  145.     }
  146.     
  147.     pb_basic.fileParam.ioCompletion=0L;
  148.     pb_basic.fileParam.ioVRefNum=vRefNum;
  149.     pb_basic.fileParam.ioNamePtr=newName;
  150.     pb_basic.fileParam.ioDirID=pb_dir.dirInfo.ioDrDirID;
  151.     pb_basic.fileParam.ioFDirIndex=0;
  152.     isHuman=PBGetCatInfo(&pb_basic, FALSE);
  153.     if (isHuman!=noErr)
  154.     {
  155.         pb_basic.fileParam.ioFlFndrInfo.fdFlags&=~0x0100;    /* clear 'initted' flag */
  156.         pb_basic.fileParam.ioCompletion=0L;
  157.         pb_basic.fileParam.ioVRefNum=vRefNum;
  158.         pb_basic.fileParam.ioNamePtr=newName;
  159.         pb_basic.fileParam.ioDirID=pb_dir.dirInfo.ioDrDirID;
  160.         pb_basic.fileParam.ioFDirIndex=0;
  161.         PBSetCatInfo(&pb_basic, FALSE);
  162.     }
  163.     
  164.     pb_move.ioCompletion=0L;
  165.     pb_move.ioNamePtr=newName;
  166.     pb_move.ioVRefNum=vRefNum;
  167.     pb_move.ioNewName=0L;
  168.     pb_move.ioNewDirID=parID;
  169.     pb_move.ioDirID=pb_dir.dirInfo.ioDrDirID;
  170.     isHuman=PBCatMove(&pb_move, FALSE);        /* move new one into system folder */
  171.     if (isHuman!=noErr)
  172.         return cantMoveNewFileErr;
  173.     
  174.     pb_basic.fileParam.ioCompletion=0L;
  175.     pb_basic.fileParam.ioNamePtr=newName;
  176.     pb_basic.fileParam.ioVRefNum=vRefNum;
  177.     pb_basic.ioParam.ioMisc="\pStartupScreen";
  178.     pb_basic.fileParam.ioDirID=parID;
  179.     isHuman=PBHRename(&pb_basic, FALSE);    /* rename new one to "StartupScreen" */
  180.     if (isHuman!=noErr)
  181.         return cantRenameNewFileErr;
  182.     
  183.     for (i=newName[0]; i>=0; i--)
  184.         gLastName[i]=newName[i];
  185.     
  186.     SaveThePrefs();
  187.     
  188.     return allsWell;
  189. }
  190.